package com.sanjiahantang.youjiarole.module.project.views.impl;

import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.module.cases.views.impl.CaseDetailActivity;
import com.sanjiahantang.youjiarole.module.project.presenters.ProjectPresenter;
import com.sanjiahantang.youjiarole.module.project.views.ProjectView;

/**
 * Created by zy on 2017/10/29.
 */

public class ProjectActivity extends BaseMvpActivity<ProjectView,ProjectPresenter>
        implements ProjectView, View.OnClickListener,BaseView.OnLoadListener {

    private ListView listView;
    private QuickAdapter<String> adapter;

    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public ProjectPresenter initPresenter() {
        return new ProjectPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_common_list);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("我的方案");
        findViewById(R.id.fl_Left).setOnClickListener(this);
        listView = (ListView) findViewById(R.id.listView);
        adapter = new QuickAdapter<String>($this,R.layout.item_case_list) {
            @Override
            protected void convert(BaseAdapterHelper helper, String item) {
                helper.getView().setPadding(0, Utils.dip2px(context,10),0,0);
                helper.setVisible(R.id.llCollect,false);
                helper.getView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, CaseDetailActivity.class);
                        startActivity(intent);
                    }
                });
            }
        };
        listView.setAdapter(adapter);
    }

    @Override
    public void initData() {
        int id = getIntent().getIntExtra(KEY_ID,0);
        if (id > 0){
            presenter.loadProjectInnerList($this,id,this);
        }else{
            Utils.showToast($this,"未找到需求单");
            finish();
        }

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }

    @Override
    public void onLoad(Object content) {
        int count = (int) content;
        adapter.clear();
        while (count > 0){
            count--;
            adapter.add("");
        }
    }
}
